﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.Util;
using Com.CMS263.PO;
using Com.CMS263.BLL;
using System.IO;
namespace Com.CMS263.Web.manage.MyStyle
{
    public partial class style_img_add : System.Web.UI.Page
    {
      public   StyleImageBLL pbll = new StyleImageBLL();
        public int MyStyleId;
        protected void Page_Load(object sender, EventArgs e)
        {
            MyStyleId = Convert.ToInt32(Request["MyStyleId"]);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string title = StringUtil.checkStr(Request["txtTitle"]);
           
            HttpPostedFile file = Request.Files["txtProductImg"];
            if (string.IsNullOrEmpty(title))
            {
                StringUtil.Alert("名称不能为空", "-1");
            }
           
            if (file.ContentLength < 5)
            {
                StringUtil.Alert("请上传图片", "-1");
            }
            //文件按天存储，没有目录就自己创建
            string strDay = DateTime.Now.ToString("yyyy-MM-dd");
            string savePath = Server.MapPath("/ArtUpFile/" + strDay);
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }
            StyleImage prod = new StyleImage();
            prod.SortId = int.Parse(Request["txtSortId"]);
            prod.FilePath =strDay+"/"+Util.UpLoadFileUtil.UpLoadFile(file, savePath);
            prod.SortId = pbll.GetMaxId();
            prod.Title = title;
            prod.StyleId = MyStyleId;
            pbll.entity = prod;
            if (pbll.Add())
            {
                StringUtil.Alert("添加成功", "photoList.aspx?MyStyleId=" + MyStyleId);
            }
            
            
        }
        Com.CMS263.PO.MyStyle pp = new Com.CMS263.PO.MyStyle();
        MyStyleBLL prodbll = new MyStyleBLL();
        public Com.CMS263.PO.MyStyle GetProduct(object obj)
        {
            int MyStyleId = Convert.ToInt32(obj);
            pp = (Com.CMS263.PO.MyStyle)prodbll.FindModelById("MyStyle", MyStyleId);
            if (pp == null || pp.Id < 1)
            {
                pp = new Com.CMS263.PO.MyStyle();
            }
            return pp;
        }

    }
}
